***Data used in the paper "Seeing is not believing: Perception of date labels
*** over food and attributes" Journal of Food Product Market (2018)
*** by Norbert Wilson, Professor, Tufts University, Ruiqing Miao, 
*** Assistant Professor, Auburn University, and Carter Weis, Cornell University
***(graduate student)

*** Data Collected from Food Waste Experiments in Auburn AL November,December 2016
*** additional data collected at LEEDR Lab Cornell Univesity Feb 2017.

clear all
estimates clear
set more off
capture log close

import excel "/Users/nwilso01/Dropbox/Food Waste/DATA/SeeisnotbelievingWilsonMiaoWeisData.xlsx", sheet("Sheet1") firstrow

gen duration=minutes(endDate-startDate)
format duration %9.2f

*** To drop trial data that the team ran ****

drop if duration<60
drop if duration>130

*** Generates uniqe id number for each respondent

gen id=SessionNum*1000+COMP

gen State=1 if id>12000
replace State=0 if State==.
label define states 0 "Alabama" 1 "New York"
label values State states


rename _1_CODE SSUB_Safety
rename _2_CODE SSUB_Nutrition
rename _3_CODE SSUB_Quality
rename _4_CODE SSUB_Taste

rename AJ DMUB_Safety
rename AL DMUB_Nutrition
rename AN DMUB_Quality
rename AP DMUB_Taste

rename AR SSBB_Safety
rename AT SSBB_Nutrition
rename __3_CODE SSBB_Quality
rename AX SSBB_Taste

rename AZ DMBB_Safety
rename BB DMBB_Nutrition
rename BD DMBB_Quality
rename BF DMBB_Taste

rename CF OneWeekRisk
rename _CODE female
rename _TEXT_CODE age
rename BL degree

*** degree==5 is for respondents who opted not to answer the question

replace degree=. if degree==5
rename BP income

replace income=10000 if income==1
replace income=25000 if income==2
replace income=65000 if income==6
replace income=75000 if income==7
replace income=85000 if income==8
replace income=95000 if income==9
replace income=110000 if income==10
replace income=115000 if income==11
replace income=125000 if income==12
replace income=135000 if income==13
replace income=145000 if income==14
replace income=155000 if income==15
replace income=165000 if income==16
replace income=175000 if income==17
replace income=185000 if income==18
replace income=195000 if income==19
replace income=215000 if income==20
gen inc=income/1000
gen lninc=ln(income)

*** The tirciles of the income used to create income groups ***
gen income33=1 if income<=85000
replace income33=0 if income33==.
gen income66=2 if income>85000 & income<=115000
replace income66=0 if income66==.
gen income100=3 if income>115000
replace income100=0 if income100==.

gen incomegroups=income33+income66+income100
replace incomegroups=. if income==21
label define incs 1 "Low Income" 2 "Middle Income" 3 "High Income" 
label values incomegroups incs
replace income=. if income==21

label define sex 0 "Male" 1 "Female"
label values female sex


rename BN race
replace race=. if race==7
label define races 2 "Black" 3 "Asian" 4 "Hispanic" 5 "White" 6 "Other"
label values race races

*** race==5 is for respondents who opted out

gen white=1 if race==5
replace white=0 if white==.

*** Replaces age written as year of birth. We assumed that the birthday had passed.

replace age=53 if age==1964

rename BR married
replace married=. if married==3
label define marry 1 "Single" 2 "Married/Partner" 
label values married marry

*** We recoded the Likert scales becasue we had coded in Qualtrics Strongly Agree=1
*** to Strongly Disagree=5. We reversed the order as suggesed by Dawn Thilmany. 

recode SSUB_Safety (1=5) (2=4) (3=3) (4=2) (5=1)
recode SSUB_Nutrition (1=5) (2=4) (3=3) (4=2) (5=1)
recode SSUB_Taste (1=5) (2=4) (3=3) (4=2) (5=1)
recode SSUB_Quality (1=5) (2=4) (3=3) (4=2) (5=1)

recode SSBB_Safety (1=5) (2=4) (3=3) (4=2) (5=1)
recode SSBB_Nutrition (1=5) (2=4) (3=3) (4=2) (5=1)
recode SSBB_Taste (1=5) (2=4) (3=3) (4=2) (5=1)
recode SSBB_Quality (1=5) (2=4) (3=3) (4=2) (5=1)

recode DMUB_Safety (1=5) (2=4) (3=3) (4=2) (5=1)
recode DMUB_Nutrition (1=5) (2=4) (3=3) (4=2) (5=1)
recode DMUB_Taste (1=5) (2=4) (3=3) (4=2) (5=1)
recode DMUB_Quality (1=5) (2=4) (3=3) (4=2) (5=1)

recode DMBB_Safety (1=5) (2=4) (3=3) (4=2) (5=1)
recode DMBB_Nutrition (1=5) (2=4) (3=3) (4=2) (5=1)
recode DMBB_Taste (1=5) (2=4) (3=3) (4=2) (5=1)
recode DMBB_Quality (1=5) (2=4) (3=3) (4=2) (5=1)

label define Likkert 1 "Strongly disagree" 2 "Somewhat disagree" ///
3 "Neither agree nor disagree" 4 "Somewhat agree" 5 "Strongly agree"
label values SSUB_Safety Likkert
label values SSUB_Nutrition Likkert
label values SSUB_Quality Likkert
label values SSUB_Taste Likkert

label values SSBB_Safety Likkert
label values SSBB_Nutrition Likkert
label values SSBB_Quality Likkert
label values SSBB_Taste Likkert

label values DMUB_Safety Likkert
label values DMUB_Nutrition Likkert
label values DMUB_Quality Likkert
label values DMUB_Taste Likkert

label values DMBB_Safety Likkert
label values DMBB_Nutrition Likkert
label values DMBB_Quality Likkert
label values DMBB_Taste Likkert
label values OneWeekRisk Likkert

label define edu 1 "High school or less" 2 "Associate Degree" 3 "College" ///
4 "Graduate" 
label values degree edu

gen colleged=1 if degree>=3
replace colleged=0 if colleged==.

*** Paired t-test of Likkert Questions about date labels for Table 2, but only for
*** product, attribute comparisons. We reshape the data to get at the other t-tests.
*** The for the other t-tests are available after the main modeling.

ttest SSUB_Safety==DMUB_Safety
ttest SSBB_Safety==DMBB_Safety

ttest SSUB_Nutrition==DMUB_Nutrition
ttest SSBB_Nutrition==DMBB_Nutrition

ttest SSUB_Quality==DMUB_Quality
ttest SSBB_Quality==DMBB_Quality

ttest SSUB_Taste==DMUB_Taste
ttest SSBB_Taste==DMBB_Taste


estpost sum DMBB* DMUB* SSBB* SSUB* female incomegroups white married age
estout using summary.xls, replace



*******************************************************************************

*****            Reshaping the data

*******************************************************************************
rename SSUB_Nutrition LK_1
rename SSUB_Safety LK_2
rename SSUB_Quality LK_3
rename SSUB_Taste LK_4

rename SSBB_Nutrition LK_5
rename SSBB_Safety LK_6
rename SSBB_Quality LK_7
rename SSBB_Taste LK_8

rename DMUB_Nutrition LK_9
rename DMUB_Safety LK_10
rename DMUB_Quality LK_11
rename DMUB_Taste LK_12

rename DMBB_Nutrition LK_13
rename DMBB_Safety LK_14
rename DMBB_Quality LK_15
rename DMBB_Taste LK_16


gen temp_1="SSUB_Nutrition"
gen temp_2="SSUB_Safety"
gen temp_3="SSUB_Quality"
gen temp_4="SSUB_Taste"

gen temp_5="SSBB_Nutrition"
gen temp_6="SSBB_Safety"
gen temp_7="SSBB_Quality"
gen temp_8="SSBB_Taste"

gen temp_9="DMUB_Nutrition"
gen temp_10="DMUB_Safety"
gen temp_11="DMUB_Quality"
gen temp_12="DMUB_Taste"

gen temp_13="DMBB_Nutrition"
gen temp_14="DMBB_Safety"
gen temp_15="DMBB_Quality"
gen temp_16="DMBB_Taste"

egen PDS_1 = concat(temp_1 id), punct(" ")
egen PDS_2 = concat(temp_2 id), punct(" ")
egen PDS_3 = concat(temp_3 id), punct(" ")
egen PDS_4 = concat(temp_4 id), punct(" ")
egen PDS_5 = concat(temp_5 id), punct(" ")
egen PDS_6 = concat(temp_6 id), punct(" ")
egen PDS_7 = concat(temp_7 id), punct(" ")
egen PDS_8 = concat(temp_8 id), punct(" ")
egen PDS_9 = concat(temp_9 id), punct(" ")
egen PDS_10 = concat(temp_10 id), punct(" ")
egen PDS_11 = concat(temp_11 id), punct(" ")
egen PDS_12 = concat(temp_12 id), punct(" ")
egen PDS_13 = concat(temp_13 id), punct(" ")
egen PDS_14 = concat(temp_14 id), punct(" ")
egen PDS_15 = concat(temp_15 id), punct(" ")
egen PDS_16 = concat(temp_16 id), punct(" ")

drop temp_*

reshape long LK_ PDS_, i(id) j(Time)
egen ProductDateSize= ends(PDS_), head punct(" ") 
egen Prodgroup= ends(ProductDateSize), head punct(_)
egen Prodgroup2= ends(ProductDateSize), tail punct(_)
egen float Product = group(Prodgroup)
egen float Product2 = group(Prodgroup2)
label define prods 1 "Deli Meat Best By" 2 "Deli Meat Use by" ///
3 "Spaghetti Sauce Best By" 4 "Spaghetti Sauce Use By"
label define prods2 1 "Nutrition" 2 "Quality" 3 "Safety" 4 "Taste"

label values Product prods
label values Product2 prods2

gen Foods=1 if Product==1 | Product==2
replace Foods=2 if Foods==.

gen Date=1 if Product==1 | Product==3
replace Date=2 if Date==.

label define treata 1 "Deli Meat" 2 "Spaghetti Sauce"
label define treatb 1 "Best by" 2 "Use by"
label values Foods treata
label values Date treatb

label define food 1 "Deli Meat" 2 "Spaghetti Sauce" 
label values Food food

xtset id

***Graph of box plots

graph box LK_, over(Product2) over(Food) over (Date)

*** Core models****

eststo, title("Nutrition"): xtreg LK_ i.Date ib2.Foods i.female ///
i.incomegroups i.white i.married i.colleged c.age##c.age c.QID210 ///
if Product2==1, vce(cluster id)
eststo, title("Quality"): xtreg LK_ i.Date ib2.Foods i.female i.incomegroups ///
 i.white i.married i.colleged c.age##c.age c.QID210 if Product2==2,///
 vce(cluster id)
eststo, title("Safety"): xtreg LK_ i.Date ib2.Foods i.female i.incomegroups ///
i.white i.married i.colleged c.age##c.age c.QID210 if Product2==3,
/// vce(cluster id)
eststo, title("Taste"): xtreg LK_ i.Date ib2.Foods i.female i.incomegroups ///
i.white i.married i.colleged c.age##c.age c.QID210 if Product2==4, ///
vce(cluster id)
eststo, title("Full"): xtreg LK_ i.Date i.Product2 ib2.Foods i.female ///
i.incomegroups i.white i.married i.colleged c.age##c.age c.QID210, ///
 vce(cluster id)
eststo, title("Full with Interaction"): xtreg LK_ i.Date##i.Product2 ///
ib2.Foods i.female i.incomegroups i.white i.married i.colleged ///
c.age##c.age c.QID210, vce(cluster id)

estout using TablesFinalsa.xls, cells(b(star label(Coef.)fmt(3))  ///
    se(label(SE) fmt(3)))///
	starlevels(* 0.10 ** 0.05 *** 0.010) legend label nobaselevels ///
	varlabels(_cons Constant) ///
	stats(r2 df_r N, labels (R-Squared df N))  replace

eststo clear

*** Model is added generates Figure 5.
xtreg LK_ i.Date##i.Product2 ib2.Foods  i.female i.incomegroups i.white ///
i.married i.colleged c.age##c.age c.QID210, vce(cluster id)
margins r.Date, over(Product2)
marginsplot

**************************************************************************************************************************************************

*** More resphaing for Paired t-tests

**************************************************************************************************************************************************
clear all
estimates clear
set more off
capture log close

import excel "/Users/nwilso01/Dropbox/Food Waste/DATA/SeeisnotbelievingWilsonMiaoWeisData.xlsx", sheet("Sheet1") firstrow

gen duration=minutes(endDate-startDate)
format duration %9.2f

drop if duration<60
drop if duration>130

gen id=SessionNum*1000+COMP

rename _1_CODE SSUB_Safety
rename _2_CODE SSUB_Nutrition
rename _3_CODE SSUB_Quality
rename _4_CODE SSUB_Taste

rename AJ DMUB_Safety
rename AL DMUB_Nutrition
rename AN DMUB_Quality
rename AP DMUB_Taste

rename AR SSBB_Safety
rename AT SSBB_Nutrition
rename __3_CODE SSBB_Quality
rename AX SSBB_Taste

rename AZ DMBB_Safety
rename BB DMBB_Nutrition
rename BD DMBB_Quality
rename BF DMBB_Taste

recode SSUB_Safety (1=5) (2=4) (3=3) (4=2) (5=1)
recode SSUB_Nutrition (1=5) (2=4) (3=3) (4=2) (5=1)
recode SSUB_Taste (1=5) (2=4) (3=3) (4=2) (5=1)
recode SSUB_Quality (1=5) (2=4) (3=3) (4=2) (5=1)

recode SSBB_Safety (1=5) (2=4) (3=3) (4=2) (5=1)
recode SSBB_Nutrition (1=5) (2=4) (3=3) (4=2) (5=1)
recode SSBB_Taste (1=5) (2=4) (3=3) (4=2) (5=1)
recode SSBB_Quality (1=5) (2=4) (3=3) (4=2) (5=1)

recode DMUB_Safety (1=5) (2=4) (3=3) (4=2) (5=1)
recode DMUB_Nutrition (1=5) (2=4) (3=3) (4=2) (5=1)
recode DMUB_Taste (1=5) (2=4) (3=3) (4=2) (5=1)
recode DMUB_Quality (1=5) (2=4) (3=3) (4=2) (5=1)

recode DMBB_Safety (1=5) (2=4) (3=3) (4=2) (5=1)
recode DMBB_Nutrition (1=5) (2=4) (3=3) (4=2) (5=1)
recode DMBB_Taste (1=5) (2=4) (3=3) (4=2) (5=1)
recode DMBB_Quality (1=5) (2=4) (3=3) (4=2) (5=1)


label define Likkert 1 "Strongly disagree" 2 "Somewhat disagree" ///
3 "Neither agree nor disagree" 4 "Somewhat agree" 5 "Strongly agree"

label values SSUB_Safety Likkert
label values SSUB_Nutrition Likkert
label values SSUB_Quality Likkert
label values SSUB_Taste Likkert

label values SSBB_Safety Likkert
label values SSBB_Nutrition Likkert
label values SSBB_Quality Likkert
label values SSBB_Taste Likkert

label values DMUB_Safety Likkert
label values DMUB_Nutrition Likkert
label values DMUB_Quality Likkert
label values DMUB_Taste Likkert

label values DMBB_Safety Likkert
label values DMBB_Nutrition Likkert
label values DMBB_Quality Likkert
label values DMBB_Taste Likkert


*******************************************************************************

*****            Reshaping the data

*******************************************************************************


rename SSUB_Nutrition LKSUB_1
rename SSUB_Safety LKSUB_2
rename SSUB_Quality LKSUB_3
rename SSUB_Taste LKSUB_4

rename SSBB_Nutrition LKSBB_1
rename SSBB_Safety LKSBB_2
rename SSBB_Quality LKSBB_3
rename SSBB_Taste LKSBB_4

rename DMUB_Nutrition LKDUB_1
rename DMUB_Safety LKDUB_2
rename DMUB_Quality LKDUB_3
rename DMUB_Taste LKDUB_4

rename DMBB_Nutrition LKDBB_1
rename DMBB_Safety LKDBB_2
rename DMBB_Quality LKDBB_3
rename DMBB_Taste LKDBB_4


gen tempSUB_1="SSUB_Nutrition"
gen tempSUB_2="SSUB_Safety"
gen tempSUB_3="SSUB_Quality"
gen tempSUB_4="SSUB_Taste"

gen tempSBB_1="SSBB_Nutrition"
gen tempSBB_2="SSBB_Safety"
gen tempSBB_3="SSBB_Quality"
gen tempSBB_4="SSBB_Taste"

gen tempDUB_1="DMUB_Nutrition"
gen tempDUB_2="DMUB_Safety"
gen tempDUB_3="DMUB_Quality"
gen tempDUB_4="DMUB_Taste"

gen tempDBB_1="DMBB_Nutrition"
gen tempDBB_2="DMBB_Safety"
gen tempDBB_3="DMBB_Quality"
gen tempDBB_4="DMBB_Taste"


egen PDSSUB_1 = concat(tempSUB_1 id), punct(" ")
egen PDSSUB_2 = concat(tempSUB_2 id), punct(" ")
egen PDSSUB_3 = concat(tempSUB_3 id), punct(" ")
egen PDSSUB_4 = concat(tempSUB_4 id), punct(" ")

egen PDSSBB_1 = concat(tempSBB_1 id), punct(" ")
egen PDSSBB_2 = concat(tempSBB_2 id), punct(" ")
egen PDSSBB_3 = concat(tempSBB_3 id), punct(" ")
egen PDSSBB_4 = concat(tempSBB_4 id), punct(" ")

egen PDSDUB_1 = concat(tempDUB_1 id), punct(" ")
egen PDSDUB_2 = concat(tempDUB_2 id), punct(" ")
egen PDSDUB_3 = concat(tempDUB_3 id), punct(" ")
egen PDSDUB_4 = concat(tempDUB_4 id), punct(" ")

egen PDSDBB_1 = concat(tempDBB_1 id), punct(" ")
egen PDSDBB_2 = concat(tempDBB_2 id), punct(" ")
egen PDSDBB_3 = concat(tempDBB_3 id), punct(" ")
egen PDSDBB_4 = concat(tempDBB_4 id), punct(" ")

drop tempS*
drop tempD*

*** Name code LKSUB_ is the Likert score for spaghetti sauce with "Use by"
*** LKDBB_ is the Likert score for deli meat with "Best by"

reshape long LKSUB_ LKSBB_ LKDUB_ LKDBB_ PDSSUB_ PDSSBB_ PDSDUB_ PDSDBB_, i(id) j(Time)

egen ProductDateSizeSUB= ends(PDSSUB_), head punct(" ") 
egen ProdgroupSSUB= ends(ProductDateSizeSUB), head punct(_)
egen ProdgroupSSUB2= ends(ProductDateSizeSUB), tail punct(_)
egen float ProductSUB = group(ProdgroupSSUB)
egen float ProductSSUB2 = group(ProdgroupSSUB2)

egen ProductDateSizeSBB= ends(PDSSBB_), head punct(" ") 
egen ProdgroupSSBB= ends(ProductDateSizeSBB), head punct(_)
egen ProdgroupSSBB2= ends(ProductDateSizeSBB), tail punct(_)
egen float ProductSBB = group(ProdgroupSSBB)
egen float ProductSSBB2 = group(ProdgroupSSBB2)

egen ProductDateSizeDUB= ends(PDSDUB_), head punct(" ") 
egen ProdgroupSDUB= ends(ProductDateSizeDUB), head punct(_)
egen ProdgroupSDUB2= ends(ProductDateSizeDUB), tail punct(_)
egen float ProductDUB = group(ProdgroupSDUB)
egen float ProductSDUB2 = group(ProdgroupSDUB2)

egen ProductDateSizeDBB= ends(PDSDBB_), head punct(" ") 
egen ProdgroupSDBB= ends(ProductDateSizeDBB), head punct(_)
egen ProdgroupSDBB2= ends(ProductDateSizeDBB), tail punct(_)
egen float ProductDBB = group(ProdgroupSDBB)
egen float ProductSDBB2 = group(ProdgroupSDBB2)


label define prods 1 "Deli Meat Best By" 2 "Deli Meat Use by" 3 "Spaghetti Sauce Best By" ///
4 "Spaghetti Sauce Use By"
label define prods2 1 "Nutrition" 2 "Quality" 3 "Safety" 4 "Taste"
*** Paired t-tests

ttest LKSUB_==LKSBB_
ttest LKDUB_==LKDBB_

**************************************************************************************************************************************************

*** More resphaing for Paired t-tests

**************************************************************************************************************************************************
clear all
estimates clear
set more off
capture log close

import excel "/Users/nwilso01/Dropbox/Food Waste/DATA/SeeisnotbelievingWilsonMiaoWeisData.xlsx", sheet("Sheet1") firstrow

gen duration=minutes(endDate-startDate)
format duration %9.2f

drop if duration<60
drop if duration>130

gen id=SessionNum*1000+COMP

rename _1_CODE SSUB_Safety
rename _2_CODE SSUB_Nutrition
rename _3_CODE SSUB_Quality
rename _4_CODE SSUB_Taste

rename AJ DMUB_Safety
rename AL DMUB_Nutrition
rename AN DMUB_Quality
rename AP DMUB_Taste

rename AR SSBB_Safety
rename AT SSBB_Nutrition
rename __3_CODE SSBB_Quality
rename AX SSBB_Taste

rename AZ DMBB_Safety
rename BB DMBB_Nutrition
rename BD DMBB_Quality
rename BF DMBB_Taste

recode SSUB_Safety (1=5) (2=4) (3=3) (4=2) (5=1)
recode SSUB_Nutrition (1=5) (2=4) (3=3) (4=2) (5=1)
recode SSUB_Taste (1=5) (2=4) (3=3) (4=2) (5=1)
recode SSUB_Quality (1=5) (2=4) (3=3) (4=2) (5=1)

recode SSBB_Safety (1=5) (2=4) (3=3) (4=2) (5=1)
recode SSBB_Nutrition (1=5) (2=4) (3=3) (4=2) (5=1)
recode SSBB_Taste (1=5) (2=4) (3=3) (4=2) (5=1)
recode SSBB_Quality (1=5) (2=4) (3=3) (4=2) (5=1)

recode DMUB_Safety (1=5) (2=4) (3=3) (4=2) (5=1)
recode DMUB_Nutrition (1=5) (2=4) (3=3) (4=2) (5=1)
recode DMUB_Taste (1=5) (2=4) (3=3) (4=2) (5=1)
recode DMUB_Quality (1=5) (2=4) (3=3) (4=2) (5=1)

recode DMBB_Safety (1=5) (2=4) (3=3) (4=2) (5=1)
recode DMBB_Nutrition (1=5) (2=4) (3=3) (4=2) (5=1)
recode DMBB_Taste (1=5) (2=4) (3=3) (4=2) (5=1)
recode DMBB_Quality (1=5) (2=4) (3=3) (4=2) (5=1)


label define Likkert 1 "Strongly disagree" 2 "Somewhat disagree" ///
3 "Neither agree nor disagree" 4 "Somewhat agree" 5 "Strongly agree"

label values SSUB_Safety Likkert
label values SSUB_Nutrition Likkert
label values SSUB_Quality Likkert
label values SSUB_Taste Likkert

label values SSBB_Safety Likkert
label values SSBB_Nutrition Likkert
label values SSBB_Quality Likkert
label values SSBB_Taste Likkert

label values DMUB_Safety Likkert
label values DMUB_Nutrition Likkert
label values DMUB_Quality Likkert
label values DMUB_Taste Likkert

label values DMBB_Safety Likkert
label values DMBB_Nutrition Likkert
label values DMBB_Quality Likkert
label values DMBB_Taste Likkert



**************************************************************************************************************************************************************


*******************************************************************************

*****            Reshaping the data

*******************************************************************************


rename SSUB_Nutrition LKNUB_1
rename SSUB_Safety LKSUB_1
rename SSUB_Quality LKQUB_1
rename SSUB_Taste LKTUB_1

rename DMUB_Nutrition LKNUB_2
rename DMUB_Safety LKSUB_2
rename DMUB_Quality LKQUB_2
rename DMUB_Taste LKTUB_2

rename SSBB_Nutrition LKNBB_1
rename SSBB_Safety LKSBB_1
rename SSBB_Quality LKQBB_1
rename SSBB_Taste LKTBB_1

rename DMBB_Nutrition LKNBB_2
rename DMBB_Safety LKSBB_2
rename DMBB_Quality LKQBB_2
rename DMBB_Taste LKTBB_2


gen tempNUB_1="SSUB_Nutrition"
gen tempSUB_1="SSUB_Safety"
gen tempQUB_1="SSUB_Quality"
gen tempTUB_1="SSUB_Taste"

gen tempNUB_2="DMUB_Nutrition"
gen tempSUB_2="DMUB_Safety"
gen tempQUB_2="DMUB_Quality"
gen tempTUB_2="DMUB_Taste"

gen tempNBB_1="SSBB_Nutrition"
gen tempSBB_1="SSBB_Safety"
gen tempQBB_1="SSBB_Quality"
gen tempTBB_1="SSBB_Taste"

gen tempNBB_2="DMBB_Nutrition"
gen tempSBB_2="DMBB_Safety"
gen tempQBB_2="DMBB_Quality"
gen tempTBB_2="DMBB_Taste"

egen PDSNUB_1 = concat(tempNUB_1 id), punct(" ")
egen PDSQUB_1 = concat(tempQUB_1 id), punct(" ")
egen PDSSUB_1 = concat(tempSUB_1 id), punct(" ")
egen PDSTUB_1 = concat(tempTUB_1 id), punct(" ")

egen PDSNBB_1 = concat(tempNBB_1 id), punct(" ")
egen PDSQBB_1 = concat(tempQBB_1 id), punct(" ")
egen PDSSBB_1 = concat(tempSBB_1 id), punct(" ")
egen PDSTBB_1 = concat(tempTBB_1 id), punct(" ")

egen PDSNUB_2 = concat(tempNUB_2 id), punct(" ")
egen PDSQUB_2 = concat(tempQUB_2 id), punct(" ")
egen PDSSUB_2 = concat(tempSUB_2 id), punct(" ")
egen PDSTUB_2 = concat(tempTUB_2 id), punct(" ")

egen PDSNBB_2 = concat(tempNBB_2 id), punct(" ")
egen PDSQBB_2 = concat(tempQBB_2 id), punct(" ")
egen PDSSBB_2 = concat(tempSBB_2 id), punct(" ")
egen PDSTBB_2 = concat(tempTBB_2 id), punct(" ")

drop tempN*
drop tempQ*
drop tempS*
drop tempT*

*** LKNUB is the Likert score for Nutrition with "Use by" over both products.
*** The "N" is for nutrition, "Q" is for quality, "S" is for safety, "T" is 
*** for taste.

reshape long LKNUB_ LKQUB_ LKSUB_ LKTUB_ LKNBB_ LKQBB_ LKSBB_ LKTBB_  ///
PDSNUB_ PDSQUB_ PDSSUB_ PDSTUB_ PDSNBB_ PDSQBB_ PDSSBB_ PDSTBB_ , i(id) j(Time)

egen ProductDateSizeNUB= ends(PDSNUB_), head punct(" ") 
egen ProdgroupSNUB= ends(ProductDateSizeNUB), head punct(_)
egen ProdgroupSNUB2= ends(ProductDateSizeNUB), tail punct(_)
egen float ProductNUB = group(ProdgroupSNUB)
egen float ProductSNUB2 = group(ProdgroupSNUB2)

egen ProductDateSizeQUB= ends(PDSQUB_), head punct(" ") 
egen ProdgroupSQUB= ends(ProductDateSizeQUB), head punct(_)
egen ProdgroupSQUB2= ends(ProductDateSizeQUB), tail punct(_)
egen float ProductQUB = group(ProdgroupSQUB)
egen float ProductSQUB2 = group(ProdgroupSQUB2)

egen ProductDateSizeSUB= ends(PDSSUB_), head punct(" ") 
egen ProdgroupSSUB= ends(ProductDateSizeSUB), head punct(_)
egen ProdgroupSSUB2= ends(ProductDateSizeSUB), tail punct(_)
egen float ProductSUB = group(ProdgroupSSUB)
egen float ProductSSUB2 = group(ProdgroupSSUB2)

egen ProductDateSizeTUB= ends(PDSTUB_), head punct(" ") 
egen ProdgroupSTUB= ends(ProductDateSizeTUB), head punct(_)
egen ProdgroupSTUB2= ends(ProductDateSizeTUB), tail punct(_)
egen float ProductTUB = group(ProdgroupSTUB)
egen float ProductSTUB2 = group(ProdgroupSTUB2)

egen ProductDateSizeNBB= ends(PDSNBB_), head punct(" ") 
egen ProdgroupSNBB= ends(ProductDateSizeNBB), head punct(_)
egen ProdgroupSNBB2= ends(ProductDateSizeNBB), tail punct(_)
egen float ProductNBB = group(ProdgroupSNBB)
egen float ProductSNBB2 = group(ProdgroupSNBB2)

egen ProductDateSizeQBB= ends(PDSQBB_), head punct(" ") 
egen ProdgroupSQBB= ends(ProductDateSizeQBB), head punct(_)
egen ProdgroupSQBB2= ends(ProductDateSizeQBB), tail punct(_)
egen float ProductQBB = group(ProdgroupSQBB)
egen float ProductSQBB2 = group(ProdgroupSQBB2)

egen ProductDateSizeSBB= ends(PDSSBB_), head punct(" ") 
egen ProdgroupSSBB= ends(ProductDateSizeSBB), head punct(_)
egen ProdgroupSSBB2= ends(ProductDateSizeSBB), tail punct(_)
egen float ProductSBB = group(ProdgroupSSBB)
egen float ProductSSBB2 = group(ProdgroupSSBB2)

egen ProductDateSizeTBB= ends(PDSTBB_), head punct(" ") 
egen ProdgroupSTBB= ends(ProductDateSizeTBB), head punct(_)
egen ProdgroupSTBB2= ends(ProductDateSizeTBB), tail punct(_)
egen float ProductTBB = group(ProdgroupSTBB)
egen float ProductSTBB2 = group(ProdgroupSTBB2)

label define prods 1 "Deli Meat Best By" 2 "Deli Meat Use by" ///
3 "Spaghetti Sauce Best By" 4 "Spaghetti Sauce Use By"
label define prods2 1 "Nutrition" 2 "Quality" 3 "Safety" 4 "Taste"
label define treata 1 "Deli Meat" 2 "Spaghetti Sauce"
label define treatb 1 "Best by" 2 "Use by"

label values ProductNUB treata
label values ProductQUB treata
label values ProductSUB treata
label values ProductTUB treata

label values ProductNBB treata
label values ProductQBB treata
label values ProductSBB treata
label values ProductTBB treata

*** Paired t-test for attributes over foods

ttest LKNUB_==LKNBB
ttest LKQUB_==LKQBB
ttest LKSUB_==LKSBB
ttest LKTUB_==LKTBB

**************************************************************************************************************************************************

*** More resphaing for Paired t-tests

**************************************************************************************************************************************************
clear all
estimates clear
set more off
capture log close

import excel "/Users/nwilso01/Dropbox/Food Waste/DATA/SeeisnotbelievingWilsonMiaoWeisData.xlsx", sheet("Sheet1") firstrow

gen duration=minutes(endDate-startDate)
format duration %9.2f

drop if duration<60
drop if duration>130

gen id=SessionNum*1000+COMP

rename _1_CODE SSUB_Safety
rename _2_CODE SSUB_Nutrition
rename _3_CODE SSUB_Quality
rename _4_CODE SSUB_Taste

rename AJ DMUB_Safety
rename AL DMUB_Nutrition
rename AN DMUB_Quality
rename AP DMUB_Taste

rename AR SSBB_Safety
rename AT SSBB_Nutrition
rename __3_CODE SSBB_Quality
rename AX SSBB_Taste

rename AZ DMBB_Safety
rename BB DMBB_Nutrition
rename BD DMBB_Quality
rename BF DMBB_Taste

recode SSUB_Safety (1=5) (2=4) (3=3) (4=2) (5=1)
recode SSUB_Nutrition (1=5) (2=4) (3=3) (4=2) (5=1)
recode SSUB_Taste (1=5) (2=4) (3=3) (4=2) (5=1)
recode SSUB_Quality (1=5) (2=4) (3=3) (4=2) (5=1)

recode SSBB_Safety (1=5) (2=4) (3=3) (4=2) (5=1)
recode SSBB_Nutrition (1=5) (2=4) (3=3) (4=2) (5=1)
recode SSBB_Taste (1=5) (2=4) (3=3) (4=2) (5=1)
recode SSBB_Quality (1=5) (2=4) (3=3) (4=2) (5=1)

recode DMUB_Safety (1=5) (2=4) (3=3) (4=2) (5=1)
recode DMUB_Nutrition (1=5) (2=4) (3=3) (4=2) (5=1)
recode DMUB_Taste (1=5) (2=4) (3=3) (4=2) (5=1)
recode DMUB_Quality (1=5) (2=4) (3=3) (4=2) (5=1)

recode DMBB_Safety (1=5) (2=4) (3=3) (4=2) (5=1)
recode DMBB_Nutrition (1=5) (2=4) (3=3) (4=2) (5=1)
recode DMBB_Taste (1=5) (2=4) (3=3) (4=2) (5=1)
recode DMBB_Quality (1=5) (2=4) (3=3) (4=2) (5=1)


label define Likkert 1 "Strongly disagree" 2 "Somewhat disagree" ///
3 "Neither agree nor disagree" 4 "Somewhat agree" 5 "Strongly agree"

label values SSUB_Safety Likkert
label values SSUB_Nutrition Likkert
label values SSUB_Quality Likkert
label values SSUB_Taste Likkert

label values SSBB_Safety Likkert
label values SSBB_Nutrition Likkert
label values SSBB_Quality Likkert
label values SSBB_Taste Likkert

label values DMUB_Safety Likkert
label values DMUB_Nutrition Likkert
label values DMUB_Quality Likkert
label values DMUB_Taste Likkert

label values DMBB_Safety Likkert
label values DMBB_Nutrition Likkert
label values DMBB_Quality Likkert
label values DMBB_Taste Likkert



**************************************************************************************************************************************************************


*******************************************************************************

*****            Reshaping the data

*******************************************************************************


rename SSUB_Nutrition LKUB_1
rename SSUB_Safety LKUB_2
rename SSUB_Quality LKUB_3
rename SSUB_Taste LKUB_4

rename DMUB_Nutrition LKUB_5
rename DMUB_Safety LKUB_6
rename DMUB_Quality LKUB_7
rename DMUB_Taste LKUB_8

rename SSBB_Nutrition LKBB_1
rename SSBB_Safety LKBB_2
rename SSBB_Quality LKBB_3
rename SSBB_Taste LKBB_4

rename DMBB_Nutrition LKBB_5
rename DMBB_Safety LKBB_6
rename DMBB_Quality LKBB_7
rename DMBB_Taste LKBB_8


gen tempUB_1="SSUB_Nutrition"
gen tempUB_2="SSUB_Safety"
gen tempUB_3="SSUB_Quality"
gen tempUB_4="SSUB_Taste"

gen tempUB_5="DMUB_Nutrition"
gen tempUB_6="DMUB_Safety"
gen tempUB_7="DMUB_Quality"
gen tempUB_8="DMUB_Taste"

gen tempBB_1="SSBB_Nutrition"
gen tempBB_2="SSBB_Safety"
gen tempBB_3="SSBB_Quality"
gen tempBB_4="SSBB_Taste"

gen tempBB_5="DMBB_Nutrition"
gen tempBB_6="DMBB_Safety"
gen tempBB_7="DMBB_Quality"
gen tempBB_8="DMBB_Taste"

egen PDSUB_1 = concat(tempUB_1 id), punct(" ")
egen PDSUB_2 = concat(tempUB_2 id), punct(" ")
egen PDSUB_3 = concat(tempUB_3 id), punct(" ")
egen PDSUB_4 = concat(tempUB_4 id), punct(" ")

egen PDSUB_5 = concat(tempUB_5 id), punct(" ")
egen PDSUB_6 = concat(tempUB_6 id), punct(" ")
egen PDSUB_7 = concat(tempUB_7 id), punct(" ")
egen PDSUB_8 = concat(tempUB_8 id), punct(" ")

egen PDSBB_1 = concat(tempBB_1 id), punct(" ")
egen PDSBB_2 = concat(tempBB_2 id), punct(" ")
egen PDSBB_3 = concat(tempBB_3 id), punct(" ")
egen PDSBB_4 = concat(tempBB_4 id), punct(" ")

egen PDSBB_5 = concat(tempBB_5 id), punct(" ")
egen PDSBB_6 = concat(tempBB_6 id), punct(" ")
egen PDSBB_7 = concat(tempBB_7 id), punct(" ")
egen PDSBB_8 = concat(tempBB_8 id), punct(" ")

drop tempUB*
drop tempBB*

*** LKUB_ is the Likert score for "Use by" and LKBB_ is the Likert score for 
*** "Best by".

reshape long LKUB_ LKBB_ PDSUB_ PDSBB_, i(id) j(Time)

egen ProductDateSizeUB= ends(PDSUB_), head punct(" ") 
egen ProdgroupSUB= ends(ProductDateSizeUB), head punct(_)
egen ProdgroupSUB2= ends(ProductDateSizeUB), tail punct(_)
egen float ProductUB = group(ProdgroupSUB)
egen float ProductSUB2 = group(ProdgroupSUB2)

egen ProductDateSizeBB= ends(PDSBB_), head punct(" ") 
egen ProdgroupSBB= ends(ProductDateSizeBB), head punct(_)
egen ProdgroupSBB2= ends(ProductDateSizeBB), tail punct(_)
egen float ProductBB = group(ProdgroupSBB)
egen float ProductSBB2 = group(ProdgroupSBB2)

label define prods 1 "Deli Meat Best By" 2 "Deli Meat Use by" 3 "Spaghetti Sauce Best By" ///
4 "Spaghetti Sauce Use By"
label define prods2 1 "Nutrition" 2 "Quality" 3 "Safety" 4 "Taste"

*** Paired t-test for "Use by" vs. "Best by" over attributes and products.

ttest LKUB_==LKBB_
